<%@page import="java.util.ArrayList"%>
<%@page import="statics.SoptVars"%>
<%@page import="comm.util.RequestManager"%>
<%@page import="comm.util.SoptHashMap"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.ParseException"%>
<%@page import="sopt.engSearch.DaumSearchProc"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	SoptHashMap hm = RequestManager.getRequest(request);
	
	ArrayList blogSearch = new ArrayList();
	ArrayList imgSearch = new ArrayList();
	ArrayList vidSearch = new ArrayList();
	
	int curPage = 1;
	if(hm!=null){
		if(hm.get("PAGE")!=null)
			curPage=Integer.parseInt(hm.get("PAGE").toString());
		if(hm.get("Q")!=null){
			blogSearch = DaumSearchProc.getResultDaumSearch(hm.get("Q").toString(),SoptVars.Menu_Category_Blog,curPage,8);
			imgSearch = DaumSearchProc.getResultDaumSearch(hm.get("Q").toString(),SoptVars.Menu_Category_Image,curPage,8);
			vidSearch = DaumSearchProc.getResultDaumSearch(hm.get("Q").toString(),SoptVars.Menu_Category_Video,curPage,8);
		}
	}
%>


<div id="blogSearch" class="blogSearch">
	<div>powered by DAUM</div>
	<div class="resultHeaders">
		<span style="float:right;">블로그 검색 결과 (<%=blogSearch.size() %>) <a href="javascript:hideResult('blogSearch');">hide</a> <a href="javascript:showResult('blogSearch');">show</a></span>
	</div>
	<div id="blogSearchContent">
	<%for(int i=0;i<blogSearch.size();i++){
		SoptHashMap tempHm = (SoptHashMap)blogSearch.get(i);
		String pubdate = tempHm.get("IMGPUBDATE").toString();
		
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
   		Date date = new Date();
		try {
			date = format.parse(pubdate);
			format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			pubdate = format.format(date);
		} catch (ParseException e1) {
		}
		
		%>
	<div class="g">
		<p class="title"><a href='<%=tempHm.get("LINK")%>' target="_blank"><%=tempHm.get("TITLE")%></a></p>
		<p class="authorPubdate"><%=tempHm.get("AUTHOR")%> - <%=pubdate%></p>
		<p class="desc"><%=tempHm.get("DESCRIPTION")%></p>
		<p class="link"><a href='<%=tempHm.get("LINK")%>' target="_blank"><%=tempHm.get("LINK")%></a></p>
		
	</div>
	<%} %>
	</div>
</div>
<div class="imgSearch">
	<div class="resultHeaders">
		<span style="float:right;">이미지 검색 결과 (<%=imgSearch.size() %>) <a href="javascript:hideResult('imgSearch');">hide</a> <a href="javascript:showResult('imgSearch');">show</a></span>
	</div>
	<div id="imgSearchContent">
	<%
	String result = "";
	for(int i=0;i<imgSearch.size();i++){
		SoptHashMap tempHm = (SoptHashMap)imgSearch.get(i);
		String title = tempHm.get("TITLE").toString();
		String link = tempHm.get("LINK").toString();
		String pubdate = tempHm.get("IMGPUBDATE").toString();
		String thumbnail = tempHm.get("THUMBNAIL").toString();
		String width = tempHm.get("WIDTH").toString();
		String height = tempHm.get("HEIGHT").toString();
   		String host = link.substring(7);
   		host = host.substring(0,host.indexOf("/"));
   		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
   		Date date;
		try {
			date = format.parse(pubdate);
			format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			pubdate = format.format(date);
		} catch (ParseException e1) {
		}
   		
   		result +=
   			"<div class='gImg'>" +
				"<p><a href='"+link+"' target='_blank'>" +
						"<img class='gImgThumb' src='"+ thumbnail+ "' width='150' />"+
   			"</a></p>" +
   			"<div class='resultknowAuthor'>" +
				pubdate+
				"</div>";
   		
   		result +=
   			"<p><a href='"+link+"' target='_blank' class='linkGreen'>"+host+"</a></p>"+
				"</div>";
	}
	%>
	<%=result %>
	<div class="clear"></div>
	</div>
</div>
<div class="vidSearch">
	<div class="resultHeaders">
		<span style="float:right;">동영상 검색 결과 (<%=vidSearch.size()%>) <a href="javascript:hideResult('vidSearch');">hide</a> <a href="javascript:showResult('vidSearch');">show</a></span>
	</div>
	<div id="vidSearchContent">
	<%
	result="<div id='videoPlayerBg'>" +
	"<div id='videoPlayerHeader'><span id='videoPlayerTitle'></span><input type='button' value='close' onclick='closeVideoLayer()'/></div>" +
	"<div id='videoPlayerLayer'></div>" +
	"</div>";
	for(int i=0;i<vidSearch.size();i++){
		SoptHashMap tempHm = new SoptHashMap();
		tempHm = (SoptHashMap)vidSearch.get(i);
		
		String title = tempHm.get("TITLE").toString();
		String cpname = tempHm.get("CPNAME").toString();
		String tag = tempHm.get("TAG").toString();
		String author = tempHm.get("AUTHOR").toString();
		String link = tempHm.get("LINK").toString();
		String pubdate = tempHm.get("IMGPUBDATE").toString();
		String thumbnail = tempHm.get("THUMBNAIL").toString();
		
		String playtime = tempHm.get("PLAYTIME").toString();
		String playcount = tempHm.get("PLAYCNT").toString();
		String player_url = tempHm.get("PLAYER_URL").toString();
		
		String host = link.substring(7);
		host = host.substring(0,host.indexOf("/"));
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date;
		try {
			date = format.parse(pubdate);
			format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			pubdate = format.format(date);
		} catch (ParseException e1) {
		}
			int playtimeMin = Integer.parseInt(playtime)/60;
			String minute = "";
			if(playtimeMin<10)minute = "0"+ playtimeMin;
			int playtimeSec = Integer.parseInt(playtime)%60;
			String sec = "";
			if(playtimeSec<10)sec = "0"+ playtimeSec;
			result +=
				"<div class='gVid'>" +
				"<div class='gVidThumbBg'><a href='"+link+"' target='_blank'>" +
						"<img class='gVidThumb' src='"+ thumbnail+ "' width='175' />"+
				"</a></div>" +
				"<div class='gVidDesc'><p><a href='"+link+"' target='_blank'>" +
				title +
				"</a>" +
				"</p>" +
				"<div class='resultknowAuthor'>" +
				author +" - "+cpname+
				"-"+
				pubdate+
				"</div>" +
				"<div class='gVidTag'>Play time: "+minute+":"+sec+
				" / Play count: " +
				playcount+
			" / TAG : " +
				tag+
				"</div>";
			
			result +=
				"<p><a style='color:green;'>"+host+"</a>";
			if(player_url.length()>0)
				result+="<input type='button' title='"+title+"' url='"+player_url+"' value='바로보기' onclick='javascript:showVideo(this)'/>";
			result+="</p>";
			
			
			result+="</div></div>";
		}
	
	result+="</div>";
	%>
	<%=result %>
	</div>
</div>
